<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="java.util.*,com.grep.extra.dao.impl.WebSiteDAOSQL,com.grep.web.manager.*,com.grep.extra.factory.data.impl.SiteUrl"%> 
<%@ include file="../common/taglibs.jsp"%>
<%@ include file="../common/ckeckuser.jsp" %>
<%
	
	//网站站点操作页面
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; 
WebSiteDAOSQL websitedaosql = new WebSiteDAOSQL();


String num = request.getParameter("index");
int index=0;
if(num==null){
	index=1;
}else{
	index = Integer.parseInt(num);
}
FenYe fenye = new FenYe();

//得到站点总数量
int count = websitedaosql.getWebSiteCount();

//每页显示数量
int pagesize = fenye.getPagesize();

//多少页数
int pagenum=0;
if(count==0){
	pagenum = 0;
	index = 0;
}else if(count <= pagesize){
	pagenum = 1;
}else{
	if(count%pagesize !=0){ 
		pagenum = count/pagesize;
		pagenum = pagenum + 1;
	}else{
		pagenum = count/pagesize;
	}
}	
if(index !=0){
	List<SiteUrl> displaywebsites =fenye.getWebSiteFenYeData(index);
	request.setAttribute("displaywebsites",displaywebsites);
	
}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>站点管理</title>
		<script src="../js/jquery-1.7.2.min.js" type="text/javascript"></script> 
       <script src="../js/websitemanager.js" type="text/javascript"></script>
       <script src="../js/common.js" type="text/javascript"></script> 
		<link href="${base }/style/style.css" type="text/css" rel="stylesheet" />
	</head>
	<body>
		<%@ include file="../common/header.jsp" %>  
	    <%@ include file="../common/manager_menu.jsp" %>  
		 
		<div id="sider_right">
			<img src="${base }/images/rightbordertop.jpg" class="imgfloat" />
			<div id="sr_cont" class="siderborder">
				<img src="${base }/images/neing.jpg" class="imgfloat" width="724" />
				<div id="newzd">					
						<span id="newzd_tit">
							<samp class="newdwei"><a href="javascript:void(0)" class="cur">所有站点</a></samp>
							<samp class="newdwei"><a href="javascript:void(0)">新建站点</a></samp>
						</span>
                        <div class="tabcontainer">
                        	<div class="sub-con cur-sub-con">
                        	  <%
	                          	if(count ==0){
	                          %>
	                        	<p>暂无数据，可点击上方新建站点添加</p>	  
	                          <%}else{ %>
                                <table id="displaytable" cellspacing="0"> 
                                    <tr> 
                                        <th width="15%" style="border-left:1px solid #DBDBDB;">站点名称</th> 
                                        <th width="20%">站点地址</th> 
                                        <th width="20%">站点logo</th> 
                                        <th width="30%">站点描述</th> 
                                        <th width="15%">操作</th> 
                                    </tr> 
                                   
                                    <c:forEach var="site" items="${displaywebsites}" varStatus="status">
										<tr> 
											<td class="tableleftborder" id="sitename_${status.index}">${site.siteName}</td> 
	                                        <td>${site.siteUrl}</td>	                                         
	                                         <td><a href="javascript:void(0)" onclick="popupDiv('displaylogo_${status.index}')" id="lookimg">点击查看图片</a></td>
	                                         <div id="displaylogo_${status.index}" class="ajaxdisplay" style="width=300px;height=300px;">
	                                         	<img src="${site.siteLogo}" alt="${site.siteName}" title="${site.siteName}" />
	                                         	<a class="p_h_x" onclick="hideDiv('displaylogo_${status.index}')" title="关闭窗口">X</a>
	                                         </div> 
	                                        <td>${site.siteDesc}</td>
	                                          <td>
	                                          	<a href="javascript:void(0)" onclick="displaymodific(${status.index});" class="displaylink" >修改</a>&nbsp;
	                                          	<a href="javascript:void(0)" class="displaylink" onclick="deletewebsite(${status.index})">删除</a>
	                                          	<span id="siteid_${status.index}" style="display:none"  >${site.id}</span>
	                                          </td>
	                                          
                                    	</tr> 				
				                    </c:forEach>
                                </table> 
                               	
                                 <div class="tabcontainer" id="fenye">	
                                  		<%	
                                  			if(pagenum !=0){
                                  				if(index==1){
                                  		%>
                                  		<span class="sfpn" style="display:none"><a href="website_manager.jsp?index=1" >首页</a></span>
                                  		<span class="sfpn" style="display:none">上一页</span>
                                  		<%}else{ %>
                                  		<span class="sfpn" style="float:left;"><a href="website_manager.jsp?index=1" >首页</a></span>
                                  		<%
                                  			if(index-1 > 0){
                                  		%>
                                  		<span class="sfpn" style="float:left"><a href="website_manager.jsp?index=<%=index-1 %>" >上一页</a></span>
                                  		<% } } }%>
                                  		<ul>
		                                 <% 
		                                 if(index < 10){
		                                	if(index <pagenum ){ 
		                                  		for(int i=1;i<11;i++){
		                                  			if(i==index){		                                  	
		                                 %>
		                                 	<li id="fenyexuanzhong"><%=i %></li>
		                                 		 <% }else{%>	
		                                 	<li><a href="website_manager.jsp?index=<%=i %>" ><%=i %></a></li>
						                <% 
		                                  			}
		                                  		}
		                                	}
		                                  }else{
						                		int prev = index-5;
						                		int next = index+6;
						                							                		
						                		for(int i = prev;i<index;i++){
						                			if(i>0){
						                				if(i==index){
						                %>
						                	<li id="fenyexuanzhong"><%=i %></li>
						                			<%}else{ %>
						                	<li><a href="website_manager.jsp?index=<%=i %>" ><%=i %></a></li>
						                <%					}
						                			}
						                		}
						                		for(int i=index;i<next;i++){
						                			if(i<pagenum+1){
						                				if(i==index){						                					
						                %>
						                	<li id="fenyexuanzhong"><%=i %></li>
						                			<%}else{ %>
						                	<li><a href="website_manager.jsp?index=<%=i %>" ><%=i %></a></li>
						                <%
						                				}
						                			}
						                		}
						                	}
						                %>
						                </ul>	
						                <%if(index==pagenum || pagenum==0){ %>
						                <span class="sfpn" style="display:none">下一页</span>
						                <span class="sfpn" style="display:none"><a href="website_manager.jsp?index=<%=pagenum %>" >末页</a></span>
						                <%}else{ %>
						                	<span class="sfpn" style="float:left"><a href="website_manager.jsp?index=<%=index+1 %>" >下一页</a></span>
						                	<span class="sfpn" style="float:left"><a href="website_manager.jsp?index=<%=pagenum %>" >末页</a></span>
						                <%} %>
						                
				                    	<span class="sfpn">当前<%=index %>页/共<%=pagenum %>页<%=count %>条数据</span>
				                    		                  		
			                  </div> 
			                   <%} %>   
                            </div> 
                            <div class="sub-con">
                                 <form method="post"> 
                                    <span  id="csdz">
										<label for="webname">站点&nbsp;名称 &nbsp;:</label>
										<input type="text" onkeyup="isnull('webname')" id="webname" class="cjinput bianju" name="sitename" />
										<span id="webname_0" class="inputtishi">站点名称不能为空</span>
									</span>
									<span id="csdz">
										<label for="weburl">站点&nbsp;地址 &nbsp;:</label>
										<input type="text" onkeyup="isnull('weburl')" id="weburl" class="cjinput bianju" name="siteurl" />
										<span id="weburl_0" class="inputtishi">站点地址不能为空</span>
									</span>
									<span  id="csdz">
										<label for="weblogourl">LOGO地址:</label>
										<input type="text" onkeyup="isnull('weblogourl')" id="weblogourl" class="cjinput bianju" name="sitelogo" />
										<span id="weblogourl_0" class="inputtishi">Logo地址不能为空</span>
									</span>
									<span  id="csdz">
										<label for="logoyulan">LOGO预览:</label>
										<input type="image" src="" title="logo" name="logo" id="logoyulan" class="bianju"  />
									</span>
									<span  id="csdz">
										<label for="zhandianmiaoshu">站点&nbsp;描述 &nbsp;:</label>
										<textarea id="zhandianmiaoshu" onkeyup="isnull('zhandianmiaoshu')" class="bianju" name="sitedesc"></textarea>
										<span id="zhandianmiaoshu_0" class="inputtishi">站点描述不能为空</span>
									</span>
                                    <input type="button" onclick="addwebsite()" value="添加" id="a2submit"/>   
                             </form>            
                         </div>  
                  </div>
                              
                   <div class="ajaxdisplay" id="displaywebsite">
	                   <form method="post">
		                   <span id="newzd_tit">
		                   		<samp id="newzdxuan">修改站点</samp>
		                   </span>
		                   <span id="csdz">
			                   <label for="sitename">站点&nbsp;名称 &nbsp;:</label>	
			                   <input type="text" onkeyup="isnull('sitename_00')" id="sitename_00" class="cjinput bianju" name="sitename" value="" />
			                   <span id="sitename_00_0" class="inputtishi">站点名称不能为空</span>
		                   </span>
		                   <span id="csdz">	
			                   <label for="siteurl">站点&nbsp;地址 &nbsp;:</label>	
			                   <input type="text" onkeyup="isnull('siteurl')" id="siteurl" class="cjinput bianju" name="siteurl" disabled="disabled" readonly="readonly" value="" />
			                   <span id="siteurl_0" class="inputtishi">站点地址不能为空</span>
		                   </span>
		                   <span id="csdz">
			                   <label for="sitelogourl">LOGO地址:</label>
			                   <input type="text" onkeyup="isnull('sitelogourl')" id="sitelogourl" class="cjinput bianju" name="sitelogo" value="" />
			                   <span id="sitelogourl_0" class="inputtishi">Logo地址不能为空</span>
		                   </span>
		                   <span id="csdz">	
			                   <label for="logolook">LOGO预览:</label>	
			                   <input type="image"  src="" height="59" id="logolook" class="bianju" />			                  
		                   </span>
		                   <span id="csdz">	
			                   <label for="sitedesc">站点&nbsp;描述 &nbsp;:</label>	
			                   <textarea id="sitedesc" onkeyup="isnull('sitedesc')" class="bianju" name="sitedesc" style="float:left"></textarea>
			                    <span id="sitedesc_0" class="inputtishi">站点描述不能为空</span>
		                   </span>
		                   <input type="hidden" value="" id="siteid" />
		                   <input type="button" onclick="modificwebsite()" value="修改" id="a2submit" />
	                   </form>
	                   	<div><a class="p_h_x" onclick="hideDiv('displaywebsite')" title="关闭窗口">X</a></div></div>
           		 </div>              
 
			</div>
			<img src="${base }/images/rightborderbuttom.jpg" class="imgfloat" />
		</div>
	</body>
</html>